﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace SGUI
{
    public static class UIModelManager 
    {
       static Dictionary<string, UIModel> models = new Dictionary<string, UIModel>();

       public static UIModel Get(string key) 
       {
           UIModel retModel = null;
           if (!models.ContainsKey(key))
           {
               retModel = (UIModel)System.Activator.CreateInstance(System.Type.GetType(key));
               retModel.Init();
               models.Add(key,retModel);
           }
           return models[key];
       }
    }

    public class UIModel
    {
        Dictionary<string, Property> propertys = new Dictionary<string,Property>();
        public Property GetProperty(string key) 
        {
            if (this.propertys.ContainsKey(key))
            {
                return this.propertys[key];
            }
            return null;
        }
        public void Init() 
        {
            foreach (System.Reflection.FieldInfo f in this.GetType().GetFields())
            {
                this.propertys.Add(f.Name,(Property)f.GetValue(this));
            }
        }
    }
}

public class TestModel :SGUI.UIModel
{
    public SGUI.Property Title = new SGUI.Property();

    public TestModel()
    {
        this.Title.Value = "吔屎啦卡鲁宾";
    }
}
